/**
 * 项目全局配置
 *
 */
var GLOBAL_CONFIG = {
    //浏览器缓存key的前缀
    cacheKeyPrefix: 'HighStandardFarmland',
    //true:启用组件使用统计
    enableComponentUsageStat: false,
    layoutConfig: {
        showCustomSelect: true,
        navToggleBtnPosition: 'rt', //lb/rt
    },
    tiandituKey: '4caf91d8465b13654a44b4f71c35e7e0', //天地图key
    amapKey: 'b755a6ccd5233c0a4c8adb365822b6b8', //高德地图js api key
    amapStyle: '49b8c078ba38a1d1e19091f39ecec9dc', //高德地图样式
    nodeSocketHost: 'socket.test.agrionline.cn', //nodejs 前端websocket推送地址
    unitId: function () {
        return tpSaaSCore.getUserInfo().userDetails.unitId;
    },
    mapGlyphs: '', //地图字体链接(mapbox-gl中要用到)
    intersectionRegionColumnName: 'town_code', //用于一张图套合计算的数据库区域编码字段名
    gisProjectTableName: 'project', //postgis库中项目的表名
    getVirtualPath: function () {
        return tpSaaSCore.getUserInfo().virtualPath + '/api_server';
    },
};


//特殊终端类型对应的pageCode
const terminalTypePageCode = {
    "34": "lwscd_34",
    "36": "lwscd_36",
    "40": "monitor_center",
    "50": "lwscd_50",
    "51": "lwscd_51",
    "53": "wsb_53",
    "56": "lwscd_56",
    "60": "wic_60",
    "61": "decoy_61",
    "62": "lwscd_mqtt_distribute"
};


function termRedirectUrl(stationId, terminalId, terminalSerial, terminalTypeId, newWindow){
    let param = {stationId, terminalSerial};
    param = {sign: tp.btoa(JSON.stringify(param))};
    let pageCode = terminalTypePageCode[terminalTypeId+""] || "";
    let virtualPath = tpSaaSCore.getUserInfo().virtualPath;
    let redirectUrl = `${virtualPath}/api_server/sap/redirect/base64?type=MONITOR&pageCode=${pageCode}&param=`;
    redirectUrl += tp.btoa(JSON.stringify(param));
    if(newWindow) {
        redirectUrl = document.location.origin + redirectUrl;
    }
    return redirectUrl;
}


//终端页面跳转
function terminalPageRedirect(stationId, terminalId, terminalSerial, terminalTypeId, newWindow) {
    const redirectUrl = termRedirectUrl(stationId, terminalId, terminalSerial, terminalTypeId, newWindow);
    if(newWindow){
        window.open(redirectUrl, "_blank");
    }else{
        window.location.href = redirectUrl;
    }
}